<template>
  <div>
    <div @click="$router.push('/search')">
      <van-search placeholder="请输入搜索关键词" />
    </div>
    <div class="container">
      <div class="left">
        <ul>
          <li :class="index==n?'active':''" @click="change(index)" v-for="(item,index) in arr" :key="item.id">{{item.catename}}</li>
        </ul>
      </div>
      <div class="right" v-if="arr.length>0">
        <p class="nav">{{arr[n].catename}}</p>
        <ul>
          <li v-for="item in arr[n].children" @click="$router.push('/list?id='+item.id+'&type=2')" :key="item.id"><img :src="$pre+item.img" alt=""><p>{{item.catename}}</p></li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import { reqAllGoods } from "../../http/http";
export default {
  data() {
    return {
      arr: [],
      n:0
    };
  },
  methods:{
    change(index){
      this.n=index

    }
  },
  activated() {
    reqAllGoods().then((res) => {
      this.arr = res.data.list;
    });
  },
};
</script>

<style scoped>
  .container{
    width: 100vw;
    height: 100vh;
    display: flex;
    background: #F2F3F2;
    overflow: hidden;
  }
  .left{
    width: 2rem;
    background: #fff;
    margin-top: 0.2rem;
  }
  .left ul li{
    list-style: none;
    text-align: center;
    line-height: 1.2rem;
    color: #333;
    margin-bottom: 0.1rem;
    font-size: 0.3rem;
    padding: 0 0.1rem;
  }
  .left ul .active{
    background: orange;
    color: #fff;
  }
  .right{
    background: #fff;
    margin: 0.2rem;
    flex: 1;
    overflow: hidden;
    border-radius: 0.1rem;
    padding: 0.4rem;
  }
  .right .nav{
    font-size: 0.4rem;
    font-weight: bold;
  }
  .right ul{
    display: flex;
    margin-top: 0.25rem;
    flex-wrap: wrap;
    justify-content: space-between;
  }
  .right ul li{
    width: 40%;
    height: 1rem;
    margin: 0.2rem 0.2rem 0.4rem 0.2rem;
  }
  .right ul li img{
    width: 100%;
    height: 100%;
  }
  .right ul li p{
    text-align: center;
    font-size: 0.3rem;
    line-height: 0.4rem;
  }
  
</style>